import { create } from 'zustand'

export interface Book {
  id: string
  title: string
  author: string
  cover_image_url: string
  description: string
  price: number
  rental_price: number
  age_range: string
  category: {
    id: string
    name: string
    type: string
  }
  rating: number
  is_featured: boolean
}

interface BookState {
  books: Book[]
  categories: Array<{ id: string; name: string; type: string; icon_url?: string }>
  currentCategory: string
  searchQuery: string
  isLoading: boolean
  setBooks: (books: Book[]) => void
  setCategories: (categories: Array<{ id: string; name: string; type: string; icon_url?: string }>) => void
  setCurrentCategory: (category: string) => void
  setSearchQuery: (query: string) => void
  setLoading: (loading: boolean) => void
}

export const useBookStore = create<BookState>((set) => ({
  books: [],
  categories: [],
  currentCategory: '',
  searchQuery: '',
  isLoading: false,
  
  setBooks: (books) => set({ books }),
  setCategories: (categories) => set({ categories }),
  setCurrentCategory: (currentCategory) => set({ currentCategory }),
  setSearchQuery: (searchQuery) => set({ searchQuery }),
  setLoading: (isLoading) => set({ isLoading })
}))